<template>
  <div>
    <a-modal
      :title=title+info.order.order_no
      :visible="order_visible"
      @cancel="handleCancel"
      :footer="null"
      :width="680"
    >
      <div v-if="info">
        <div class="hd-box">
          <span>创建时间：{{info.order.created_at|formatDate}}</span>
          <span>经办人：{{info.order.operator}}</span>
        </div>
        <div class="table-box">
          <a-table :columns="orderColumns" :data-source="orderdata" :pagination="false">
            <span slot="unit_price" slot-scope="text,record">
              <span v-if="record.project_type==1">
                <span v-if="record.price_type==1">￥{{record.unit_price}}/课时</span>
                <span v-if="record.price_type==2">￥{{record.unit_price}}/天</span>
              </span>
              <span v-else-if="record.project_type==2">￥{{record.unit_price}}/件</span>
              <span v-else-if="record.project_type==3">￥{{record.unit_price}}/笔</span>
            </span>

             <span slot="classhours" slot-scope="text,record">
                <span v-if="record.project_type==1">
                  <span v-if="record.price_type==1">{{record.buy_number}}课时</span>
                  <span
                    v-if="record.price_type==2"
                  >{{record.buy_start_time}}至{{record.buy_end_time}}</span>
                </span>
                <span v-else-if="record.project_type==2">{{record.surplus_buy_number}}件</span>
                <span v-else-if="record.project_type==3">{{record.surplus_buy_number}}笔</span>
              </span>
              <span slot="giveclasshours" slot-scope="text,record">
                <span v-if="record.project_type==1">
                  <span v-if="record.surplus_give_number!=0">
                    <span v-if="record.price_type==1">{{record.surplus_give_number}}</span>
                    <span
                      v-else-if="record.price_type==2&&record.surplus_give_number!=0"
                    >至{{record.month_buy_end_time}}</span>
                  </span>
                  <span v-else>-</span>
                </span>

                <span v-if="record.project_type==2">
                  <span v-if="record.give_number!=0">{{record.give_number}}</span>
                  <span v-else>-</span>
                </span>

                <span v-if="record.project_type==3">
                  <span v-if="record.give_number!=0">{{record.give_number}}</span>
                  <span v-else>-</span>
                </span>
              </span>

              <span slot="signing_price" slot-scope="text,record">
                <span v-if="record.surplus_buy_number">
                      ￥{{record.unit_price*record.buy_number}}
                      <!-- <span v-if="record.discount">
                        <span
                          v-if="JSON.parse(record.discount).type==1"
                        >{{Number(record.surplus_buy_number*record.unit_price-JSON.parse(record.discount).value)}}</span>
                        <span v-else-if="JSON.parse(record.discount).type==2&&JSON.parse(record.discount).value">
                          {{Number(record.surplus_buy_number*record.unit_price*JSON.parse(record.discount).value)}}
                        </span>
                      </span>
                    </span>
                    <span v-else>--</span> -->
                </span>
              </span>
          </a-table>
        </div>
        <div style="text-align:right;padding-top:10px;">
          <div v-if="info.discount">直减/折扣：
            <span v-if="JSON.parse(info.discount).type==1"> -￥{{JSON.parse(info.discount).value||'0'}}</span>
            <span v-else>{{JSON.parse(info.discount).value+'折'||'-'}}</span>
           </div>
          <!-- <div>赠送余额：-￥{{info.give_number}}</div> -->
          <div>小计：<span style="color: #ff8534;font-size: 18px;">￥{{info.signing_price}}</span> </div>
        </div>
        
      </div>
      <div v-else>暂无数据</div>
    </a-modal>
  </div>
</template>

<script>
export default {
  data() {
    return {
      title:'订单号：',
      order_visible: false,
      info: {order:{}},
      orderdata: [],
      orderColumns: [
        {
          title: '购买项目',
          dataIndex: 'buy_project',

          // scopedSlots: { customRender: 'name' },
        },
        {
          title: '定价标准',
          scopedSlots: { customRender: 'unit_price' },
        },
        {
          title: '购买数量',
        //   dataIndex: 'unit_price',

          scopedSlots: { customRender: 'classhours' },
        },
        {
          title: '赠送数量',
         scopedSlots: { customRender: 'giveclasshours' }
          // scopedSlots: { customRender: 'name' },
        },
        {
          title: '总价',
          scopedSlots: { customRender: 'signing_price' },
        },
      ],
    }
  },
  methods: {
    showModel(data) {
      let parmas=JSON.parse(JSON.stringify(data))
      if(parmas.discount){
          if(JSON.parse(parmas.discount).type==1&&JSON.parse(parmas.discount).value!=0){
              parmas.unit_price=((Number(parmas.signing_price)+Number(JSON.parse(parmas.discount).value))/parmas.buy_number).toFixed(2)
          }
          if(JSON.parse(parmas.discount).type==2&&JSON.parse(parmas.discount).value!=0){
              parmas.unit_price=((Number(parmas.signing_price)/(Number(JSON.parse(parmas.discount).value/10)))/parmas.buy_number).toFixed(2)
          }
      }
      this.info = parmas
      console.log(this.info, 'zzzzzzz')
      this.orderdata = []
      this.orderdata.push(this.info)
      this.order_visible = true
    },
    handleCancel() {
      this.order_visible = false
    },
  },
}
</script>

<style lang="less" scoped>
.hd-box {
  padding-bottom: 15px;
  span {
    margin-right: 15px;
  }
}
</style>